Skip to content

resource delay in db : Async wait for [Cancelled]#233

Closed
nishika26 wants to merge 9 commits intomainfrom
bug/delay_response
Closed

resource delay in db : Async wait for [Cancelled]#233
nishika26 wants to merge 9 commits intomainfrom
bug/delay_response

Conversation

@nishika26
Copy link
Copy Markdown
Collaborator

@nishika26 nishika26 commented Jun 17, 2025

Summary

Target issue is #217
Explain the motivation for making this change. What existing problem does the pull request solve?
we'll be implementing a temporary solution using asyncio.wait_for(). This will allow us to:

Start the background task (like creating the collection or updating the vector store).

Wait for the task to complete within a specified timeout. If the task finishes within the timeout, we send a success response. This ensures that the response, which includes the collection ID, will only be sent after the task is completed, so the collection is already present in the database and we avoid 'no row found' errors.

After using Python's time.time() to measure the time taken by the background task, it took around 7.67 seconds to complete when I uploaded an example file used in Dalgo's data analysis feature. Given this, we can estimate a timeout of approximately 15-20 seconds. Any task that finishes within that window will trigger a response before the timeout.

Notes

A few additional changes I’ve made:

  • Updated def create_collection to async def create_collection since await can only be used within async def functions. Reference

  • Switched to using an async test client to properly test asynchronous route handlers.

  • Installed the pytest-asyncio library, which is required for running async tests with pytest.

  • Logging few important parameters such as - INFO - Collection created: 425111c7-25a3-42d3-b373-c97202d9aad5 | Time: 7.514757871627808s | Files: 1 |Sizes:[137.57] KB |Types: ['txt']

  • To log file size(s) of files being uploaded, this logic was used to first calculate the file size and then the logic was added to core/cloud/storage.py

@nishika26 nishika26 self-assigned this Jun 17, 2025
@nishika26 nishika26 added bug Something isn't working dalgo-migration labels Jun 17, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 17, 2025

Codecov Report

Attention: Patch coverage is 88.77551% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/core/cloud/storage.py 16.66% 5 Missing ⚠️
backend/app/api/routes/collections.py 88.00% 3 Missing ⚠️
.../api/routes/collections/test_create_collections.py 95.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@nishika26 nishika26 changed the title async wait for Response delay : Async wait for Jun 18, 2025
@nishika26 nishika26 linked an issue Jun 18, 2025 that may be closed by this pull request
@nishika26 nishika26 changed the title Response delay : Async wait for delay in creation : Async wait for Jun 18, 2025
@nishika26 nishika26 marked this pull request as ready for review June 18, 2025 06:29
@nishika26 nishika26 moved this to In Progress in Kaapi-dev Jun 18, 2025
@nishika26 nishika26 changed the title delay in creation : Async wait for resource delay in db : Async wait for Jun 18, 2025
request,
payload,
)
# Start the background task asynchronously
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason it is here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving it for any future reference, although it is self explanatory but still just in case

@nishika26 nishika26 changed the title resource delay in db : Async wait for resource delay in db : Async wait for [Cancelled] Jun 19, 2025
@nishika26 nishika26 removed bug Something isn't working dalgo-migration labels Jun 19, 2025
@nishika26 nishika26 removed this from Kaapi-dev Jun 19, 2025
@nishika26 nishika26 closed this Jun 24, 2025
@nishika26 nishika26 deleted the bug/delay_response branch June 24, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants